package cn.yeziji.netty.config.mq;

import cn.yeziji.forum.common.key.RabbitMQConfig;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 私聊聊天室 MQ 配置
 *
 * @author gzkemays
 * @since 2022/11/08 10:30 PM
 */
@Configuration
public class PrivateChatMessageConfig {

  @Bean
  public Queue privateChatQueue() {
    return new Queue(RabbitMQConfig.PRIVATE_CHAT_MSG, true, false, false);
  }

  @Bean
  public Queue privateChatDaoQueue() {
    return new Queue(RabbitMQConfig.PRIVATE_CHAT_MSG_DAO, true, false, false);
  }

  @Bean
  public DirectExchange privateChatExchange() {
    return new DirectExchange(RabbitMQConfig.PRIVATE_CHAT_MSG_EXCHANGE, true, false);
  }

  @Bean
  public Binding bindPrivateChatDao() {
    return BindingBuilder.bind(privateChatDaoQueue())
        .to(privateChatExchange())
        .with(RabbitMQConfig.PRIVATE_CHAT_MSG_DAO_ROUTING_KEY);
  }

  @Bean
  public Binding bindPrivateChat() {
    return BindingBuilder.bind(privateChatQueue())
        .to(privateChatExchange())
        .with(RabbitMQConfig.PRIVATE_CHAT_MSG_ROUTING_KEY);
  }
}
